package com.seventh.blecore.test;

import android.util.Log;

import androidx.annotation.NonNull;
import androidx.annotation.VisibleForTesting;

import com.seventh.blecore.ByteArray;
import com.seventh.blecore.Utils;

import java.util.Arrays;

/**
 * @author chengxin
 * create at 2021/4/20
 * description:
 */
@VisibleForTesting
public class UnityHelper {

    private UnityCallback callback;

    public void setHelper(@NonNull UnityCallback callback) {
        this.callback = callback;
    }

    public void callAndroid() {
        //unity Main thread
        Log.e("unity", "是否在主线程:" + Utils.isMainThread());
        Log.e("unity", "Thread Name:" + Thread.currentThread());

        callback.callBoolean(true);
        byte b = 1;
        callback.callByte(b);
        byte[] array = {1, 2, 3, 4, 5, 6};

        callback.callByteArray(new ByteArray(array));
        callback.callJavaObject(new ByteArray(array));
        callback.callFloat(0.1f);
        callback.callDouble(0.2);
        callback.callInt(129);
        callback.callString("android 调用 Unity");
        callback.callJavaObject(Action.CONNECT);
    }

    public byte[] getByteArray() {
        return new byte[]{1, 2, 3, 4, 5, 6};
    }
    //报错
    //public String[] getStringArray() {
    //    return new String[]{"a", "b", "c", "d"};
    //}
    //报错
    //public void callArray(String[] array) {
    //    Log.e("unity", Arrays.toString(array));
    //}

    public void callArray(int[] array) {
        Log.e("unity", Arrays.toString(array));
    }

    public void callArray(byte[] array) {
        Log.e("unity", Arrays.toString(array));
    }
}
